package com.quxiu.system.service.impl;

import com.quxiu.common.core.utils.uuid.Sequence;
import com.quxiu.system.service.IdService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

@Slf4j
@Service
public class IdServiceImpl implements IdService {
    // 基于雪花算法的ID生成器
    private Sequence sequence;

    /**
     * 初始化
     */
    @PostConstruct
    private void init() {
        sequence = new Sequence(null);
    }

    /**
     * 获取下一个ID
     *
     * @return 下一个ID
     */
    @Override
    public long nextId() {
        return sequence.nextId();
    }
}
